/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.os.dao.zakharov;

import edu.os.dao.zakharov.interfacedao.RegistrationDAO;
import edu.os.dao.zakharov.interfacedao.UsersDAO;
import java.math.BigDecimal;
import javax.annotation.Resource;
import javax.ejb.SessionContext;

public class Facade {

    private RegistrationDAO registrationDAO;
    private UsersDAO usersDAO;

    private Facade() {
        DAOFactory dAOFactory = DAOFactory.getDAOFactory(EnumDataSource.ORACLE);
        registrationDAO = dAOFactory.getRegistrationDAO();
        usersDAO = dAOFactory.getUsersDAO();
    }

    private static class SingletonHolder {

        private static final Facade instance = new Facade();
    }
    
    @Resource
    private SessionContext sessionContext;
    
    public static Facade getInstance() {
        return SingletonHolder.instance;
    }

    public void registerUser(String surname, String name, String patronymic,
            String email, String country, String city, String login, String password) {
        
        try {
            BigDecimal newReg = registrationDAO.addRegistration(surname, name, patronymic,
                    email, country, city);
            BigDecimal newUser = usersDAO.addUser(login, password, newReg);
        } catch (Exception e) {
            e.printStackTrace();
            sessionContext.setRollbackOnly();
        }
    }
}
